package com.kuang.service.role;

import com.kuang.dao.BaseDao;
import com.kuang.dao.role.RoleDao;
import com.kuang.dao.role.RoleDaoImpl;
import com.kuang.pojo.Role;
import org.junit.Test;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class RoleServiceImpl implements RoleService {
    //引入Dao
    private RoleDao roleDao;
    public RoleServiceImpl() {
        roleDao=new RoleDaoImpl();
    }

    public List<Role> getRoleList()  {
//        System.out.println("RoleServiceImpl--->getRoleList");
        List<Role> roles = null;
        Connection connection = null;
        try {
         connection = BaseDao.getConnection();

            roles = roleDao.getRoleList(connection);

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            BaseDao.closeResource(connection,null,null);
        }
        return roles;
    }
    @Test
    public void test4(){
    RoleServiceImpl roleService = new RoleServiceImpl();
    List<Role> roleList = roleService.getRoleList();
   for (Role role:roleList)
   {
     System.out.println(role.getRoleName());
   }
}
}
